<%@page import="java.util.Vector"%>
<%@page import="board.BoardVo"%>
<%@page import="board.Board"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>게시판 리스트</title>
<style>
#board_list{
	widtj: 100%;
}

#board_list_title{

}

.blt{
	display: inline-block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
#b_l_t_serial{
  width: 10%;
}
#b_l_t_mid{
  width: 10%;
}
#b_l_t_subject{
  width: 25%;
}
#b_l_t_content{
  width: 35%;
}
#b_l_t_file{
  width: 10%;
}
#b_l_t_count{
  width: 5%;
}
#board_list_body{

}
.page_bt{
	width: 30px;
	height: 30px;
	background-color: orange;
	border: 1px solid purple; 
	border-radius:5px;
}
</style>

<script>
function getId(id){ return document.getElementById(id);}
var url = "index2.jsp?inc_center=./board/";

function init(){
	url = "index2.jsp?inc_center=./board/";
	
	if(getId('btnFind') != null){
		
		getId('btnFind').onclick = function(){
			community_form.action = url + "list.jsp";
			community_form.submit();
		}
	}
}

function goPage(page){
	var ff = document.community_form;
	ff.nowPage.value = page;
	ff.action = "index2.jsp?inc_center=./board/list.jsp";
	ff.submit();
}

function btn_write(){
	location.href = "index2.jsp?inc_center=./board/register.jsp";	
}
function view(serial){
	location.href = "index2.jsp?inc_center=./board/view.jsp&serial=" + serial;
}
</script>
</head>
<body>
<jsp:useBean id="boardVo" class="board.BoardVo"/>
<jsp:setProperty property="*" name="boardVo"/>

<%
//********************************************************************
//                            검색어 세션 처리 
//********************************************************************
// 검색어 세션에 저장하기 위해서 하는 작업

if(request.getMethod().equals("POST")){
	session.setAttribute("find", boardVo.getFind());
}else{
	if(session.getAttribute("find") != null){
		boardVo.setFind((String)session.getAttribute("find"));
	}
}

//********************************************************************
//                          페이지 정보 유지
//********************************************************************

if(request.getParameter("nowPage") == null){
	if(session.getAttribute("nowPage") != null)
	boardVo.setNowPage((Integer)session.getAttribute("nowPage"));
}else{
	session.setAttribute("nowPage", boardVo.getNowPage());
}

//********************************************************************
//                  게시판의 종류를 선별하는 부분
//********************************************************************
String part = (String)session.getAttribute("part");
boardVo.setPart(part);

Board bb = new Board();
bb.setVo(boardVo);
bb.setNowPage(boardVo.getNowPage());

Vector<BoardVo> vo = bb.list();
%>

<div id="board_list">
	<h1>게시판(<%=part%>)</h1>

<!-- 검색 영역 -->
	<form name="community_form" method="post" action="">
		<!-- 뷰에 들어가기 전에 쳤던 검색어를 유지하기 위해서 value 값에다가 getFind() 한다 -->
		<input type="text" name="find" id="find" value="<%=boardVo.getFind()%>"> 
		<input type="button" value="검색" id="btnFind">
		<input type="hidden" name="nowPage" value="<%=bb.getNowPage()%>">
	</form>
	
	
	<div> 전체갯수 : <%=bb.getTotSize()%></div>
	<div> 전체페이지수 : <%=bb.getTotPage()%></div>
	<div> 블럭의 갯수 : <%=bb.getBlockSize()%></div>
	<div> 현재블럭 : <%=bb.getNowBlock()%></div>
	<div> 시작페이지 : <%=bb.getStartPage()%></div>
	<div> 끝 페이지 : <%=bb.getEndPage()%></div>
	<div> 시작번호 : <%=bb.getStartNo()%></div>
	<div> 끝 번호 : <%=bb.getEndNo()%></div>
	<br/>
	
	
	<div id="board_list_title">
		<div class="blt" id="b_l_t_serial">시리얼</div>
		<div class="blt" id="b_l_t_mid">아이디</div>
		<div class="blt" id="b_l_t_subject">제 목</div>
		<div class="blt" id="b_l_t_content">내 용</div>
		<div class="blt" id="b_l_t_file">파 일</div>
		<div class="blt" id="b_l_t_count">조회</div>
	</div>
	<hr/>
	<br/>
	
	<div id="board_list_body">
		<%
		for(int i=0; i<vo.size(); i++){
			BoardVo bv = vo.get(i);
		%>
			<div class="blt" id="b_l_t_serial"><a href="#" onclick="view(<%=bv.getSerial()%>)"><%=bv.getSerial()%></a></div>
			<div class="blt" id="b_l_t_mid"><%=bv.getMid()%></div>
			<div class="blt" id="b_l_t_subject"><%=bv.getSubject()%></div>
			<div class="blt" id="b_l_t_content"><a href="#" onclick="view(<%=bv.getSerial()%>)"><%=bv.getContent()%></a></div>
			<div class="blt" id="b_l_t_file"><%=bv.getFilename()%></div>
			<div class="blt" id="b_l_t_count"></div>
			<br/>
		<%} %>
	</div>
	<br/><br/>
	<input type="button" value="글 등록" onclick="btn_write()">
	<br/><br/>
	
	<!-- 페이지 분리 영역 -->
	<div>
		<%if(bb.getNowBlock()>1) {%>
		<input type="button" class="page_bt" onclick="goPage(1)" value="맨처음">
		<input type="button" class="page_bt" onclick="goPage(<%=bb.getStartPage() -1%>)" value="이전">
		<% }%>
		[
		<%for(int p =bb.getStartPage(); p<=bb.getEndPage(); p++) {%>
		<input type="button" class="page_bt" onclick="goPage(<%=p%>)" value="<%=p%>">
		<%} %>
		]
		<%if(bb.getNowBlock() < bb.getTotBlock()){ %>
		<input type="button" class="page_bt" onclick="goPage(<%=bb.getEndPage() + 1%>)" value="다음">
		<input type="button" class="page_bt" onclick="goPage(<%=bb.getTotPage()%>)" value="맨끝">
		<%} %>
	</div>
</div>
<script>
init();
</script>
</body>
</html>